package com.quyunshuo.module.home.fragment.home

import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import com.quyunshuo.edwinusetime.base.utils.BarUtils
import com.quyunshuo.edwinusetime.common.ui.BaseFragment
import com.quyunshuo.module.home.databinding.HomeFragmentHomeBinding
import com.quyunshuo.module.home.fragment.compose.HomePage
import com.quyunshuo.module.home.manager.PermissionUtils
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

/**
 * @author DBoy 2021/7/6 <p>
 * - 文件描述 : 测试fragment
 */
@AndroidEntryPoint
class HomeFragment : BaseFragment<HomeFragmentHomeBinding, HomeViewModel>() {
    private val TAG = "HomeFragment"

        override val mViewModel by viewModels<HomeViewModel>()
    override fun createVB() = HomeFragmentHomeBinding.inflate(layoutInflater)
//    override val mViewModel: HomeViewModel by activityViewModels()


    override fun HomeFragmentHomeBinding.initListener() {

    }

    override fun HomeFragmentHomeBinding.initView() {
        BarUtils.setStatusBarLightMode(requireActivity(), false)

    }

    override fun onResume() {
        super.onResume()
        if (PermissionUtils.hasUsageStatsPermission(requireContext())) {
            mViewModel.loadAppUsageStats(requireContext())
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
    }

    override fun initObserve() {
        lifecycleScope.launch {
            mViewModel.appUsageList.collect{
                mBinding.composeView.setContent {
                    HomePage(it)
                }
            }
        }

    }

    override fun initRequestData() {
    }


}